Moving -PdisallowExecution logic out of build.py and into gradlew and replacing it with -PverifyUpToDate which both runs Gradle once and then also runs Gradle again, verifying that the second build is up-to-date. This means build.py can invoke fewer Gradle builds Then if build.py fails, it can be easier for developers to identify how to reproduce the failure using gradlew invocations These gradlew executions are then more familiar to developers and can be more easily customized Bug: 140265313 Test: ./gradlew :annotation:annotation:assemble -PverifyUpToDate # and see that this runs Gradle twice and passes Test: ./gradlew help -PverifyUpToDate # and see that Gradle runs twice and also that Gradle complains that the help task is not up-to-date Test: ./gradlew help # and see that Gradle runs once Test: echo syntax error >> build.gradle && ./gradlew help && echo success # and see that 'success' is not echoed Change-Id: If9707075193a4918526035df2f985b0deaf046a4 
diff --git a/busytown/androidx.sh b/busytown/androidx.sh index 725ffdc..f94d78b 100755 --- a/busytown/androidx.sh +++ b/busytown/androidx.sh 
@@ -8,5 +8,5 @@  fi  mkdir -p "$DIST_DIR"   -python3 "$SCRIPT_DIR/build.py" "doBoth" "doVerifyRerun" DIST_DIR="$(cd $DIST_DIR && pwd)" --no-daemon "buildOnServer" +python3 "$SCRIPT_DIR/build.py" "doBoth" DIST_DIR="$(cd $DIST_DIR && pwd)" --no-daemon "buildOnServer" -PverifyUpToDate  python3 "$SCRIPT_DIR/merge_outputs.py" DIST_DIR="$(cd $DIST_DIR && pwd)" "mergeBuildInfo" 
diff --git a/busytown/build.py b/busytown/build.py index 85039a7..b1a7ceb 100755 --- a/busytown/build.py +++ b/busytown/build.py 
@@ -25,8 +25,6 @@  doCompose (do the compose build)  doAndroidX (do the androidx build) (default if no '-do*' argument passed, due to being most common use case)  doDryRun (prevents commands form being run, but commands are still printed: dry-run the commands) - doVerifyRerun (runs commands a second time and verifies that no work was done, and everything is cached) - (these args are case sensitive)    DIST_DIR=<a path to a directory> if this is not passed, the default value is out/dist.  Should be absolute or relative to e.g. androidx-master-dev/ @@ -40,14 +38,14 @@    def main():  move_to_base_dir() - which_builds, dry_run, verify_rerun, dist_dir, gradle_args = parse_args() + which_builds, dry_run, dist_dir, gradle_args = parse_args()  androidx_base_command, compose_base_command = compute_gradle_commands(dist_dir) - if DO_ANDROIDX in which_builds: run_command(" ".join(androidx_base_command + gradle_args), dry_run=dry_run, verify_rerun=verify_rerun) - if DO_COMPOSE in which_builds: run_command(" ".join(compose_base_command + gradle_args), dry_run=dry_run, verify_rerun=verify_rerun) + if DO_ANDROIDX in which_builds: run_command(" ".join(androidx_base_command + gradle_args), dry_run=dry_run) + if DO_COMPOSE in which_builds: run_command(" ".join(compose_base_command + gradle_args), dry_run=dry_run)    def parse_args():  which_builds = [DEFAULT] - dry_run = False; verify_rerun = False + dry_run = False  dist_dir = "out/dist"  gradle_args = []  for arg in sys.argv: @@ -56,7 +54,6 @@  which_builds.append(arg)  which_builds.remove(DEFAULT)  elif arg == DO_DRY_RUN: dry_run = True # if we are mocking, we print but do not run commands - elif arg == DO_VERIFY_RERUN: verify_rerun = True # re-run the command with -PdisallowExecution to verify everything is cached  elif "dist_dir" in arg.lower():  dist_dir = arg.split("=")[1]  dist_dir = remove_suffix(dist_dir, '/') @@ -67,11 +64,11 @@  else: gradle_args.append(arg)  if which_builds == [DEFAULT]: which_builds = [DO_ANDROIDX] # default is androidx  if DO_BOTH in which_builds: which_builds = [DO_ANDROIDX, DO_COMPOSE] - return which_builds, dry_run, verify_rerun, dist_dir, gradle_args + return which_builds, dry_run, dist_dir, gradle_args    def compute_gradle_commands(dist_dir):  androidx_base_command = ["DIST_DIR="+dist_dir, OUT_DIR_ARG, ANDROID_HOME_ARG, GRADLEW, PROJECT_DIR_ARG]  compose_base_command = ["DIST_DIR="+dist_dir+ui, OUT_DIR_ARG+ui, ANDROID_HOME_ARG, GRADLEW_COMPOSE, PROJECT_DIR_ARG+ui]  return androidx_base_command, compose_base_command   -if __name__ == "__main__": main() \ No newline at end of file +if __name__ == "__main__": main() 
diff --git a/busytown/constants_and_utils.py b/busytown/constants_and_utils.py index 9e4a623..f548361 100644 --- a/busytown/constants_and_utils.py +++ b/busytown/constants_and_utils.py 
@@ -20,7 +20,7 @@  SKIPPED_ARG_SUFFIXES = ["python", ".py", "build"]  HELP_SYNTAX_LIST = ["help", "?", "man", "-h"]   -DO_ANDROIDX, DO_COMPOSE, DO_BOTH, DO_DRY_RUN, DO_VERIFY_RERUN = "doAndroidx", "doCompose", "doBoth", "doDryRun", "doVerifyRerun" +DO_ANDROIDX, DO_COMPOSE, DO_BOTH, DO_DRY_RUN = "doAndroidx", "doCompose", "doBoth", "doDryRun"  BUILD_COMMANDS = [DO_ANDROIDX, DO_COMPOSE, DO_BOTH]  DEFAULT = "DEFAULT"   @@ -49,12 +49,10 @@  if string.endswith(suffix): return string[:-len(suffix)]  else: return string   -def run_command(commandText, dry_run=False, verify_rerun=False): +def run_command(commandText, dry_run=False):  if not dry_run:  print('Running "' + commandText + '"')  result = os.system(commandText)  assert(os.WEXITSTATUS(result)) == 0 # stop if the command failed  else:  print('Not running "' + commandText + '"') - if verify_rerun: - run_command(commandText + " -PdisallowExecution", dry_run) 
diff --git a/gradlew b/gradlew index 243699d..724283c 100755 --- a/gradlew +++ b/gradlew 
@@ -215,13 +215,22 @@  TMPDIR_ARG="-Djava.io.tmpdir=$TMPDIR"  fi   -if "$JAVACMD" "${JVM_OPTS[@]}" $TMPDIR_ARG -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain $HOME_SYSTEM_PROPERTY_ARGUMENT $TMPDIR_ARG "$XMX_ARG" "$@"; then - exit 0 -else - # Print AndroidX-specific help message if build fails - # Have to do this build-failure detection in gradlew rather than in build.gradle - # so that this message still prints even if buildSrc itself fails - echo - echo See also development/diagnose-build-failure for help with build failures in this project. - exit 1 +function runGradle() { + if "$JAVACMD" "${JVM_OPTS[@]}" $TMPDIR_ARG -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain $HOME_SYSTEM_PROPERTY_ARGUMENT $TMPDIR_ARG "$XMX_ARG" "$@"; then + return 0 + else + # Print AndroidX-specific help message if build fails + # Have to do this build-failure detection in gradlew rather than in build.gradle + # so that this message still prints even if buildSrc itself fails + echo + echo See also development/diagnose-build-failure for help with build failures in this project. + exit 1 + fi +} + +runGradle "$@" +# Check whether we were given the "-PverifyUpToDate" argument +if [[ " ${@} " =~ " -PverifyUpToDate " ]]; then + # Re-run Gradle, and verify that the tasks are up-to-date + runGradle "$@" -PdisallowExecution  fi